local nya__miji = fk.CreateSkill {

  name = "nya__miji",

  tags = {  },

}



nya__miji:addEffect(fk.EventPhaseStart, {
  name = "nya__miji",
  anim_type = "drawcard",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(nya__miji.name) and player.phase == Player.Finish then
      if not player:hasSkill("nya__play", true) then
        return table.find(player.room.alive_players, function(p) return p:isWounded() end)
      else
        return player:isWounded()
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = player:getLostHp()
    if not player:hasSkill("nya__play", true) then
      n = math.max(table.unpack(table.map(room.alive_players, function(p) return p:getLostHp() end)))
    end
    player:drawCards(n, nya__miji.name)
    if not player.dead and player:getHandcardNum() >= n then
      room:setPlayerMark(player, nya__miji.name, n)
      local success, dat = room:askForUseActiveSkill(player, "nya__miji_active", "#nya__miji-give:::"..n, true)
      room:setPlayerMark(player, nya__miji.name, 0)
      if success then
        local dummy = Fk:cloneCard("dilu")
        dummy:addSubcards(dat.cards)
        room:obtainCard(dat.targets[1], dummy, false, fk.ReasonGive)
      end
    end
  end,
})

return nya__miji